package com.sinosoft.perfect.system._worksite.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.po.TWorksite;
import com.sinosoft.perfect.system._worksite.dataFormat.IWorksiteGridDataFormat;
import com.sinosoft.perfect.system._worksite.service.IWorksiteService;

@SuppressWarnings("serial")
public class WorksiteAction extends BaseAction {

	private IWorksiteService iworksiteService;

	private IWorksiteGridDataFormat worksiteGridDataFormat;

	private TWorksite tworksite;

	public IWorksiteService getIworksiteService() {
		return iworksiteService;
	}
	public void setIworksiteService(IWorksiteService iworksiteService) {
		this.iworksiteService = iworksiteService;
	}
	public IWorksiteGridDataFormat getWorksiteGridDataFormat() {
		return worksiteGridDataFormat;
	}
	public void setWorksiteGridDataFormat(
			IWorksiteGridDataFormat worksiteGridDataFormat) {
		this.worksiteGridDataFormat = worksiteGridDataFormat;
	}
	public TWorksite getTworksite() {
		return tworksite;
	}
	public void setTworksite(TWorksite tworksite) {
		this.tworksite = tworksite;
	}

	public String worksiteGrid() throws IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String resultXml = null;
		try {
			List<TWorksite> worksites = iworksiteService.selectByTWorksite(tworksite);
			resultXml = worksiteGridDataFormat.dataFormatWorksiteGrid(worksites);

		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		PrintWriter out = response.getWriter();
		out.print(resultXml);
		out.flush();
		out.close();
		return null;
	}

}
